package com.example.hospitalmanagement.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.activity.DeskDoctorActivity
import com.example.hospitalmanagement.activity.OutpatientInquiryActivity
import com.example.hospitalmanagement.activity.OutpatientPaymentActivity
import com.example.hospitalmanagement.activity.RegisterActivity
import com.example.hospitalmanagement.adapter.ServiceFragmentAdapter
import com.example.hospitalmanagement.bean.DiagnosisAndTreatmentItem
import com.example.hospitalmanagement.databinding.FragmentServiceBinding
import kotlinx.android.synthetic.main.fragment_service.*

/**
 * 诊疗服务页面Fragment
 */
class ServiceFragment : Fragment() {
    private lateinit var adapter: ServiceFragmentAdapter
    private lateinit var hospitalizedAdapter: ServiceFragmentAdapter
    private lateinit var fragmentService: FragmentServiceBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        fragmentService = DataBindingUtil.inflate(
            inflater, R.layout.fragment_service, container, false
        )
        return fragmentService.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        outpatient_clinic_item.layoutManager = GridLayoutManager(requireActivity(), 4)
        val dataList: MutableList<DiagnosisAndTreatmentItem> = mutableListOf(
            DiagnosisAndTreatmentItem(
                R.mipmap.make_an_appointment_for_registration,
                "预约挂号"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.intelligent_referra,
                "智能导诊"
            ),

            DiagnosisAndTreatmentItem(
                R.mipmap.outpatient_payment,
                "门诊支付"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.outpatient_inquiry,
                "门诊查询"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.intelligent_waiting_for_diagnosis,
                "智能候诊"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.pretest_screening,
                "预选筛查"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.online_inquiry,
                "在线问诊"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.the_virus_cold_zone,
                "病毒感冒专区"
            ),
        )
        adapter = ServiceFragmentAdapter(requireActivity())
        adapter.dataList = dataList
        outpatient_clinic_item.adapter = adapter

        hospitalized_item.layoutManager = GridLayoutManager(requireActivity(), 4)
        val hospitalizedDataList: MutableList<DiagnosisAndTreatmentItem> = mutableListOf(
            DiagnosisAndTreatmentItem(
                R.mipmap.daily_list,
                "每日清单"
            )
        )
        hospitalizedAdapter = ServiceFragmentAdapter(requireActivity())
        hospitalizedAdapter.dataList = hospitalizedDataList
        hospitalized_item.adapter = hospitalizedAdapter

        adapter.setListener {
            when (it) {
                0 -> {
                    startActivity(Intent(requireActivity(), RegisterActivity().javaClass))
                }
                1 -> {
                }
                2 -> {
                    startActivity(Intent(requireActivity(), OutpatientPaymentActivity().javaClass))
                }
                3 -> {
                    startActivity(Intent(requireActivity(), OutpatientInquiryActivity().javaClass))
                }
                4 -> {
                }
                5 -> {
                }
                6 -> {
                }
                7 -> {
                }
            }
        }
        hospitalizedAdapter.setListener {
            when (it) {
                0 -> {
                }
            }
        }
    }
}